package leetcode.code172;

import java.util.HashMap;
import java.util.Map;

public class Solution2 implements ISolution {

	public static void main(String[] args) {
		Solution2 so = new Solution2();
		for (int i = 1; i < 26; i++) {
			int num = so.trailingZeroes(i);
			if (num != 0)
				System.out.println(i + " 的阶乘结果有: " + num);
		}
	}

	@Override
	public int trailingZeroes(int n) {
		int count5 = 0;
		Map<Integer, Integer> map5 = new HashMap<>();
		for (int i = 1; i <= n; i++) {
			int i5 = 0;
			if(map5.containsKey(i)) {
				i5 = map5.get(i);
			}
			if (i * 5 <= n) {
				count5 += 1 + i5;
				map5.put(i * 5, 1 + i5);
			} else {
				break;
			}
		}
		return count5;
	}

}
